﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;

namespace Domain.Service.ObjectCache
{
 
    /// <summary>
    /// 对象缓存   
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public sealed class CacheBase
    {
        /// <summary>
        /// Lock对象，线程安全所用
        /// </summary>
        private static object syncRoot = new Object();
        /// <summary>
        /// 数据实体
        /// </summary>
        public static volatile object Instance = null;
        /// <summary>
        /// 缓存数据
        /// </summary>
        static object _data;
        /// <summary>
        /// 实体构造方法
        /// </summary>
        /// <param name="data"></param>
        public CacheBase(object data)
        {
            _data = data;
        }
        /// <summary>
        /// 类构造方法
        /// </summary>
        static CacheBase()
        {
            ReLoad(_data);
        }

        /// <summary>
        /// 重新加载数据结果集
        /// </summary>
        /// <returns></returns>
        public static void ReLoad(object data)
        {
            lock (syncRoot)
            {
                Instance = data;
            }
        }
    }
}
